﻿using DevExpress.XtraEditors;
using DevExpress.XtraReports.UI;
using DXApplicationTangche.report;
using DXApplicationTangche.service;
using DXApplicationTangche.UC.报表.service;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DXApplicationTangche.UC.报表
{
    public partial class Form抖音客户订单及热销 : DevExpress.XtraEditors.XtraForm
    {
        private List<Douyin热销VO> list = new List<Douyin热销VO>();

        public Form抖音客户订单及热销()
        {
            InitializeComponent();
            this.refreshData();
        }
        public void refreshData()
        {
            //  抖音客户订单
            this.gridControl抖音客户订单.DataSource = 抖音报表service.get抖音客户订单1(this.dateTimePicker选择日期.Value.ToString());
            this.gridView抖音客户订单.RefreshData();
            //  抖音和有赞商品对照表
            this.gridControl抖音和有赞商品对照表.DataSource = 抖音报表service.get抖音和有赞商品对照表();
            this.gridView抖音和有赞商品对照表.RefreshData();
            // 热销款
            DataTable dt = 抖音报表service.getViewSemiCheckExceptionDao();
            foreach (DataRow item in dt.Rows)
            {
                list.Add(new Douyin热销VO(item));
            }
            this.gridControl抖音热销.DataSource = list;
            this.gridView抖音热销.RefreshData();
        }

        private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
        {
            this.gridControl抖音客户订单.DataSource = 抖音报表service.get抖音客户订单1(this.dateTimePicker选择日期.Value.ToString());
            this.gridView抖音客户订单.RefreshData();
        }

        private void simpleButton导出客户订单_Click(object sender, EventArgs e)
        {
            //this.gridView抖音客户订单.ExportToXlsx(@"D:\导出excel\新建 Microsoft Excel 工作表.xlsx");//固定地址导出文件
            SaveFileDialog fileDialog = new SaveFileDialog();
            fileDialog.Title = "导出Excel";
            fileDialog.Filter = "Excel文件(*.xls)|*.xls";
            DialogResult dialogResult = fileDialog.ShowDialog(this);
            if (dialogResult == DialogResult.OK)
            {
                DevExpress.XtraPrinting.XlsExportOptions options = new DevExpress.XtraPrinting.XlsExportOptions();
                this.gridView抖音客户订单.ExportToXls(fileDialog.FileName);
                DevExpress.XtraEditors.XtraMessageBox.Show("保存成功！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                //选择地址保存文件
            }
        }

        private void gridView1_CellMerge(object sender, DevExpress.XtraGrid.Views.Grid.CellMergeEventArgs e)
        {
            if (e.Column.Name.Equals("gridColumn图片"))
            {
                Image image1 = (Image)gridView抖音热销.GetRowCellValue(e.RowHandle1, e.Column);
                Image image2 = (Image)gridView抖音热销.GetRowCellValue(e.RowHandle1, e.Column);
                e.Merge = image1 == image2;
                e.Handled = true;
            }
        }

        //导出为PDF
        private void simpleButton导出热销pdf_Click(object sender, EventArgs e)
        {
            //this.gridView抖音热销.ShowPrintPreview();//ShowPrintPreview相当于系统自带的打印预览可以输出为pdf
            XtraReport2 re = new XtraReport2(list);
            ReportPrintTool tool定制 = new ReportPrintTool(re);
            tool定制.ShowPreviewDialog();
        }
    }

    public class Douyin热销VO
    {
        public String productname { get; set; }
        public String sharetitle { get; set; }
        public String price { get; set; }
        public String stylecode { get; set; }
        public String materialcode { get; set; }
        public String barcode { get; set; }
        public String imageurl { get; set; }
        public Image pic { get; set; }
        public Douyin热销VO(DataRow dr)
        {
            this.productname = dr["productname"].ToString();
            this.sharetitle = dr["sharetitle"].ToString();
            this.price = dr["price"].ToString();
            this.stylecode = dr["stylecode"].ToString();
            this.materialcode = dr["materialcode"].ToString();
            this.barcode = dr["barcode"].ToString();
            this.imageurl = dr["imageurl"].ToString();
            try
            {
                this.pic = FileService.GetImageByUrl(this.imageurl);
            }
            catch { }
        }
    }
}